package com.shaoshaohuo.app.utils;

import java.text.NumberFormat;

/**
 * String 工具类
 * @author YinSF
 * @createDate 2015-11-12
 */
public class StringUtil {

	/**
	 * 判断是否为空
	 * @param target
	 * @return
	 */
	public static final boolean isEmpty(String target) {
		if (target == null)
			return true;
		if ("".equals(target.trim()))
			return true;
		
		return false;
	}

	public static boolean isNumericEmpty(String msg) {
		return isEmpty(msg) || "0".equals(msg);
	}

	public static boolean isEmpty(CharSequence temp) {
		if (temp == null)
			return true;
		return isEmpty(temp.toString());
	}

	public static String formatDouble(double value) {
		NumberFormat format = NumberFormat.getInstance();
		format.setMaximumFractionDigits(2);
		return format.format(value);
	}

	/**
	 * 身份证号加密，如110124198804111010，加密后显示110124********1010
	 * @param idnum
	 * @return
	 */
	public static String formatIdNum(String idnum) {
		if (idnum == null) {
			return "";
		}
		idnum = idnum.trim();
		if (idnum.length() != 18) {
			return idnum;
		}
		String start = idnum.substring(0, 6);
		String end = idnum.substring(14);
		return start + "********" + end;
	}
}
